//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "UnitLogIn.h"
#include "UnitProf.h"
#include "UnitStud.h"
#include "UnitRegister.h"
#include "Course.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormLogIn *FormLogIn;
//---------------------------------------------------------------------------
__fastcall TFormLogIn::TFormLogIn(TComponent* Owner)
   : TForm(Owner)
{
}
//---------------------------------------------------------------------------




void __fastcall TFormLogIn::ComboBox1Change(TObject *Sender)
{
   if(ComboBox1->ItemIndex!=0){
        Edit1->Visible=true;
        Edit2->Visible=true;
        Button1->Visible=true;
        Button2->Visible=true;
   }
   else{
        Edit1->Visible=false;
        Edit2->Visible=false;
        Button1->Visible=false;
        Button2->Visible=false;
   }
}
//---------------------------------------------------------------------------

void __fastcall TFormLogIn::Button1Click(TObject *Sender)
{
        if(ComboBox1->ItemIndex==1){
                ADOQuery1->SQL->Text="Select USERNAME, PASSWORD \
                                From STUDENT \
                                Where USERNAME='"+Edit1->Text+"' \
                                AND PASSWORD='"+Edit2->Text+"'";
                ADOQuery1->ExecSQL();
                ADOQuery1->Active=true;

                if((Edit1->Text==DBEdit1->Text)&&(Edit2->Text==DBEdit2->Text)){
                        FormStud->Show();
                        FormLogIn->Hide();
                }
                else ShowMessage("error");
        }
   else if(ComboBox1->ItemIndex==2){
                ADOQuery1->SQL->Text="Select USERNAME, PASSWORD \
                                From PROFFESSOR \
                                Where USERNAME='"+Edit1->Text+"' \
                                AND PASSWORD='"+Edit2->Text+"'";
                ADOQuery1->ExecSQL();
                ADOQuery1->Active=true;

                if((Edit1->Text==DBEdit1->Text)&&(Edit2->Text==DBEdit2->Text)){



                        
                        FormProf->Show();
                        FormLogIn->Hide();
                }
                else ShowMessage("error");
   }

}
//---------------------------------------------------------------------------
void __fastcall TFormLogIn::Button2Click(TObject *Sender)
{
   FormRegister->Show();
   FormLogIn->Hide();
   if(ComboBox1->ItemIndex==1){
        FormRegister->ADOQuery1->SQL->Text="Select * From STUDENT";
        FormRegister->ADOQuery1->ExecSQL();
        FormRegister->ADOQuery1->Active=true;
        FormRegister->Label4->Visible=true;
        FormRegister->Label5->Visible=true;
        FormRegister->Edit4->Visible=true;
        FormRegister->Edit5->Visible=true;
   }
   else if(ComboBox1->ItemIndex==2){
        FormRegister->ADOQuery1->SQL->Text="Select * From PROFFESSOR";
        FormRegister->ADOQuery1->ExecSQL();
        FormRegister->ADOQuery1->Active=true;
        FormRegister->Label4->Visible=false;
        FormRegister->Label5->Visible=false;
        FormRegister->Edit4->Visible=false;
        FormRegister->Edit5->Visible=false;
   }
}
//---------------------------------------------------------------------------
void __fastcall TFormLogIn::Edit1Click(TObject *Sender)
{
        Edit1->Text="";
}
//---------------------------------------------------------------------------


void __fastcall TFormLogIn::Edit2Click(TObject *Sender)
{
        Edit2->Text="";        
}
//---------------------------------------------------------------------------

void __fastcall TFormLogIn::ExitButtonClick(TObject *Sender)
{
        FormLogIn->Close();        
}
//---------------------------------------------------------------------------





